
#ifndef _TTG_THREADS_WIN32_WIN32EVENTS_
#define _TTG_THREADS_WIN32_WIN32EVENTS_
#include "Common/Definitions.h"

#include "../Events.h"
#include <windows.h>

namespace ttg
{
	namespace threads
	{
		namespace win32
		{
			//Fast implementation of the event.
			//Thread doesn't sleep, it waits (like Chuck Norris) in while (1) loop.
			class Win32FastEvent :public ttg_internal::threads::ThreadEvent
			{
				private:
					volatile LONG flag;	//0 - not setted, 1 - setted.
				public:
					//Creates configured unsetted event.
					Win32FastEvent();
					//Current thread begins waiting for event.
					virtual void wait();
					//Waits for event or time interval elapsing.
					//Note: time in seconds.
					virtual void wait(double time);
					//Wake waiter thread.
					virtual void rise();
			};

			//Classic implementation of event.
			class Win32SlowEvent :public ttg_internal::threads::ThreadEvent
			{
				private:
					HANDLE ev;
				public:
					//Creates event.
					//In case of error throws Error().
					Win32SlowEvent();
					//Current thread begins waiting for event.
					//In case of error throws Error().
					virtual void wait();
					//Waits for event or time interval elapsing.
					//Note: time in seconds.
					virtual void wait(double time);
					//Wake waiter thread.
					//In case of error throws Error().
					virtual void rise();
					~Win32SlowEvent();
			};
		}
	}
}

namespace ttg
{
	namespace threads
	{
		typedef win32::Win32FastEvent FastEvent;
		typedef win32::Win32SlowEvent SlowEvent;
	}
}

#endif
